home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / vm / vmList.c < prev    next >
C/C++ Source or Header  |  1991-06-21  |  4KB  |  137 lines

  1. /* 
  2.  * vmList.c --
  3.  *
  4.  *    Routines for maintaining lists
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that this copyright
  10.  * notice appears in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/vm/RCS/vmList.c,v 9.3 91/06/21 12:07:11 jhh Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21. #include <list.h>
  22. #include <sys.h>
  23. #include <vm.h>
  24. #include <vmInt.h>
  25.  
  26.  
  27. /*
  28.  * ----------------------------------------------------------------------------
  29.  *
  30.  * VmListInsert --
  31.  *
  32.  *    Insert the list element pointed to by itemPtr into a List after 
  33.  *    destPtr.  Perform a primitive test for self-looping by returning
  34.  *    failure if the list element is being inserted next to itself.
  35.  *
  36.  * Results:
  37.  *    If neither List_Links structure is NIL, they are assumed to be valid
  38.  *    and SUCCESS is returned.  If either one is NIL then FAILURE is
  39.  *    returned.  
  40.  *
  41.  * Side effects:
  42.  *    The list containing destPtr is modified to contain itemPtr.
  43.  *
  44.  * ----------------------------------------------------------------------------
  45.  */
  46. void
  47. VmListInsert(itemPtr, destPtr)
  48.     register    List_Links *itemPtr;    /* structure to insert */
  49.     register    List_Links *destPtr;    /* structure after which to insert it */
  50. {
  51.     if (itemPtr->nextPtr != (List_Links *) NIL ||
  52.     itemPtr->prevPtr != (List_Links *) NIL) {
  53.     panic("VmListInsert: Inserting element twice.\n");
  54.     }
  55.  
  56.     if (itemPtr == (List_Links *) NIL || destPtr == (List_Links *) NIL
  57.         || !itemPtr || !destPtr || (itemPtr == destPtr)) {
  58.     panic("VmListInsert: Bad item or dest ptr.\n");
  59.     }
  60.     itemPtr->nextPtr = destPtr->nextPtr;
  61.     itemPtr->prevPtr = destPtr;
  62.     destPtr->nextPtr->prevPtr = itemPtr;
  63.     destPtr->nextPtr = itemPtr;
  64. }
  65.  
  66.  
  67. /*
  68.  * ----------------------------------------------------------------------------
  69.  *
  70.  * VmListRemove --
  71.  *
  72.  *    Remove a list element from the list in which it is contained.
  73.  *
  74.  * Results:
  75.  *    If the list element is invalid or is the list header, FAILURE is 
  76.  *    returned.  Otherwise SUCCESS is returned.
  77.  *
  78.  * Side effects:
  79.  *    The given structure is removed from its containing list.
  80.  *
  81.  * ----------------------------------------------------------------------------
  82.  */
  83. void
  84. VmListRemove(itemPtr)
  85.     register    List_Links *itemPtr;    /* list element to remove */
  86. {
  87.     if (itemPtr->nextPtr == (List_Links *) NIL ||
  88.     itemPtr->prevPtr == (List_Links *) NIL) {
  89.     panic("VmListRemove: Item not on list.\n");
  90.     }
  91.     if (itemPtr == (List_Links *) NIL || itemPtr == itemPtr->nextPtr
  92.         || !itemPtr) {
  93.     panic("VmListRemove: Bad itemPtr.\n");
  94.     }
  95.     itemPtr->prevPtr->nextPtr = itemPtr->nextPtr;
  96.     itemPtr->nextPtr->prevPtr = itemPtr->prevPtr;
  97.     itemPtr->prevPtr = (List_Links *) NIL;
  98.     itemPtr->nextPtr = (List_Links *) NIL;
  99. }
  100.  
  101.  
  102. /*
  103.  * ----------------------------------------------------------------------------
  104.  *
  105.  * VmListMove --
  106.  *
  107.  *    Move the list element referenced by itemPtr to follow destPtr.
  108.  *
  109.  * Results:
  110.  *    If either list element is invalid, FAILURE is returned.
  111.  *    Otherwise SUCCESS is returned.
  112.  *
  113.  * Side effects:
  114.  *    List ordering is modified.
  115.  *
  116.  * ----------------------------------------------------------------------------
  117.  */
  118. void
  119. VmListMove(itemPtr, destPtr)
  120.     register List_Links *itemPtr; /* list element to be moved */
  121.     register List_Links *destPtr; /* element after which it is to be placed */
  122. {
  123.     if (itemPtr == (List_Links *) NIL || destPtr == (List_Links *) NIL
  124.         || !itemPtr || !destPtr) {
  125.     panic("VmListMove: Bad item or dest ptr.\n");
  126.     }
  127.     /*
  128.      * It is conceivable that someone will try to move a list element to
  129.      * be after itself.
  130.      */
  131.     if (itemPtr != destPtr) {
  132.     VmListRemove(itemPtr);
  133.     VmListInsert(itemPtr, destPtr);
  134.     }    
  135. }
  136.  
  137.